#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A股股票查询分析器 - 快速启动
提供一些常用的预设查询选项
"""

from stock_analyzer import StockAnalyzer
import sys

def quick_search_hot_concepts():
    """快速搜索热门概念股"""
    hot_concepts = [
        "人工智能", "新能源汽车", "芯片概念", "5G概念", 
        "医疗器械", "新能源", "军工概念", "区块链"
    ]
    
    print("热门概念股快速查询")
    print("=" * 30)
    
    for i, concept in enumerate(hot_concepts, 1):
        print(f"{i}. {concept}")
    
    try:
        choice = int(input("\n请选择概念编号 (1-8): ")) - 1
        if 0 <= choice < len(hot_concepts):
            selected_concept = hot_concepts[choice]
            print(f"\n正在查询 {selected_concept} 概念股...")
            
            analyzer = StockAnalyzer()
            results = analyzer.filter_stocks(concept=selected_concept)
            analyzer.display_results(results)
        else:
            print("无效选择")
    except ValueError:
        print("请输入有效数字")

def quick_search_price_ranges():
    """快速搜索不同价格区间的股票"""
    price_ranges = [
        (5, 15, "低价股 (5-15元)"),
        (15, 30, "中低价股 (15-30元)"),
        (30, 60, "中价股 (30-60元)"),
        (60, 100, "中高价股 (60-100元)"),
        (100, 300, "高价股 (100-300元)")
    ]
    
    print("不同价格区间股票快速查询")
    print("=" * 35)
    
    for i, (min_p, max_p, desc) in enumerate(price_ranges, 1):
        print(f"{i}. {desc}")
    
    try:
        choice = int(input("\n请选择价格区间 (1-5): ")) - 1
        if 0 <= choice < len(price_ranges):
            min_price, max_price, desc = price_ranges[choice]
            print(f"\n正在查询 {desc} 股票...")
            
            analyzer = StockAnalyzer()
            results = analyzer.filter_stocks(price_range=(min_price, max_price))
            analyzer.display_results(results)
        else:
            print("无效选择")
    except ValueError:
        print("请输入有效数字")

def quick_search_market_caps():
    """快速搜索不同市值区间的股票"""
    market_caps = [
        (50, 200, "中小市值 (50-200亿)"),
        (200, 500, "中等市值 (200-500亿)"),
        (500, 1000, "大市值 (500-1000亿)"),
        (1000, 5000, "超大市值 (1000-5000亿)")
    ]
    
    print("不同市值区间股票快速查询")
    print("=" * 35)
    
    for i, (min_mv, max_mv, desc) in enumerate(market_caps, 1):
        print(f"{i}. {desc}")
    
    try:
        choice = int(input("\n请选择市值区间 (1-4): ")) - 1
        if 0 <= choice < len(market_caps):
            min_mv, max_mv, desc = market_caps[choice]
            print(f"\n正在查询 {desc} 股票...")
            
            analyzer = StockAnalyzer()
            results = analyzer.filter_stocks(market_value_range=(min_mv, max_mv))
            analyzer.display_results(results)
        else:
            print("无效选择")
    except ValueError:
        print("请输入有效数字")

def quick_search_uptrend():
    """快速查询走势向上的优质股票"""
    print("走势向上的优质股票查询")
    print("=" * 30)
    print("正在筛选市盈率为正且最近一个月走势向上的股票...")
    print("注意：此查询可能需要5-10分钟，请耐心等待...")
    
    analyzer = StockAnalyzer()
    results = analyzer.filter_stocks(positive_pe_and_uptrend=True)
    analyzer.display_results(results)

def main():
    """主函数"""
    print("A股股票查询分析器 - 快速启动")
    print("=" * 40)
    
    while True:
        print("\n请选择快速查询类型:")
        print("1. 热门概念股查询")
        print("2. 不同价格区间查询")
        print("3. 不同市值区间查询")
        print("4. 走势向上优质股票查询")
        print("5. 启动完整版程序")
        print("0. 退出")
        
        choice = input("\n请输入选择 (0-5): ").strip()
        
        try:
            if choice == '0':
                print("感谢使用，再见！")
                break
            elif choice == '1':
                quick_search_hot_concepts()
            elif choice == '2':
                quick_search_price_ranges()
            elif choice == '3':
                quick_search_market_caps()
            elif choice == '4':
                quick_search_uptrend()
            elif choice == '5':
                print("启动完整版程序...")
                from stock_analyzer import main as full_main
                full_main()
            else:
                print("无效选择，请重新输入")
        
        except KeyboardInterrupt:
            print("\n\n用户中断程序")
            break
        except Exception as e:
            print(f"查询过程中发生错误: {e}")
            print("请检查网络连接或稍后重试")

if __name__ == "__main__":
    main() 